#include <stdio.h>
#include <memory.h>

bool use[ 4 ], chongfu[ 10000 ], space;
int stack[ 4 ];
int num[ 4 ];

void dfs( int n )
{
    if ( n == 4 )
    {
        int t = stack[ 0 ] * 1000 + stack[ 1 ] * 100 + stack[ 2 ] * 10 + stack[ 3 ];
        if ( chongfu[ t ] )
        {
            if ( space ) printf(" ");
            else space = true;
            printf("%d", t);
            chongfu[ t ] = false;
        }
    }
    else    if ( n < 4 )
    {
        int i;
        for ( i = 0; i < 4; i++ )
        {
            if ( use[ i ] )
            {
                use[ i ] = false;
                stack[ n ] = num[ i ];
                dfs( n + 1 );
                use[ i ] = true;
            }
        }
    }
}

int main( )
{
    bool blank = false;
    while ( scanf("%d%d%d%d", &num[ 0 ], &num[ 1 ], &num[ 2 ], &num[ 3 ] ) != EOF )
    {
        if ( num[ 0 ] + num[ 1 ] + num[ 2 ] + num[ 3 ] == 0 )
            break;
        if ( blank ) printf("\n");
        else blank = true;
        int i, j;
        memset( use, 1, sizeof( use ) );
        memset( chongfu, 1, sizeof( chongfu ) );
        for ( i = 0; i < 3; i++ )
            for ( j = i + 1; j < 4; j++ )
                if ( num[ i ] > num[ j ] )
                    num[ i ] ^= num[ j ] ^= num[ i ] ^= num[ j ];
        for ( i = 0; i < 4; i++ )
        {
            if ( num[ i ] != 0 )
            {
                space = false;
                use[ i ] = false;
                stack[ 0 ] = num[ i ];
                dfs( 1 );
                use[ i ] = true;
                if ( i > 0 )
                {
                    if ( num[ i ] != num[ i - 1 ] ) printf("\n");
                }
                else printf("\n");
            }
        }
    }
    return 0;
}
